package com.iwdnb.gkgz.common.model.dto;

import java.io.Serializable;
import java.math.BigDecimal;

import com.iwdnb.bmnf.common.utils.BooleanUtils;
import com.iwdnb.gkgz.common.utils.BigDecimalUtils;
import lombok.Data;

/**
 * StrategyParamDto
 *
 * @date 2024-02-06 17:16:38
 **/
@Data
public class StrategyImageStatisticDTO implements Serializable {

    /**
     * 图形走势编码
     */
    private String imageCode;

    private int successCount = 0;

    private BigDecimal successSum = BigDecimal.ZERO;

    private BigDecimal successRate = BigDecimal.ZERO;

    private int failCount = 0;

    private BigDecimal failSum = BigDecimal.ZERO;

    private BigDecimal failRate = BigDecimal.ZERO;

    private int totalCount;

    private BigDecimal totalSum;

    private BigDecimal totalRate;

    /**
     * 收益类型,win/loss/allWin/allLoss/balance
     */
    private String profitType;

    private String valid;

    public void caculate() {
        setTotalCount(successCount + failCount);
        setTotalSum(successSum.add(failSum));
        setTotalRate(BigDecimalUtils.divide(totalSum, BigDecimalUtils.of(totalCount)));
        if (successCount > 0) {
            setSuccessRate(BigDecimalUtils.divide(successSum, BigDecimalUtils.of(successCount)));
        }
        if (failCount > 0) {
            setFailRate(BigDecimalUtils.divide(failSum, BigDecimalUtils.of(failCount)));
        }
        if (successCount == 0) {
            profitType = "allLoss";
        } else if (failCount == 0) {
            profitType = "allWin";
        } else if (BigDecimalUtils.isGe(totalRate, new BigDecimal(2.5))) {
            profitType = "win";
        } else if (BigDecimalUtils.isLe(totalRate, new BigDecimal(2.2))) {
            profitType = "loss";
        } else {
            profitType = "balance";
        }

        if (profitType.equals("allLoss") || profitType.equals("allWin")) {
            valid = totalCount > 5 ? BooleanUtils.TRUE : BooleanUtils.FALSE;
        } else {
            valid = totalCount > 10 ? BooleanUtils.TRUE : BooleanUtils.FALSE;
        }
    }

}
